class Info:
    def __init__(self,num,name,score):
        self.name = name
        self.num = num
        self.score = score

    def __str__(self):
        return '学号:{} 姓名:{}  成绩:{}'.format(self.num,self.name,self.score)
class Menu:
    def __init__(self,name):
        self.name = name
        self.lst = []
        self.dic = {}
    def aped(self,stu):
        self.lst.append(stu)
        self.dic[stu.num] = stu
    def sort_stu(self,key = None,reverse =  False):
        self.lst.sort(key = key,reverse = reverse)#这个当初是想先排序后输出，近期会加上。
    def display(self):
        for s in self.lst:
            print(s)
    def writearead(self,label):
        if label == 1:
            fo = open("data.txt","w")
            for stu in self.lst:
                fo.write("%s,%s,%s\n"%(stu.num,stu.name,stu.score))
            fo.close()
        else:
            fot = open("data.txt","r")
            fot.close()
            

def UI():
    print("=" * 50)
    print("1.输入数据")
    print("2.格式化输出学生成绩")
    print("3.存盘")
    print("4.读盘")
    print("请输入您的选择:")

menu = Menu('hath')#"类“的运用可能还不太行，写这个的时候
#匆匆学习了一下，想知道“类”的使用有哪些坑
while True:
        UI()
        key = int(input("请输入功能:"))
        print("="*50)
        if key in range(0,5):
            if key == 1:
                print("添加学生信息:")
                num = int(input("学号:"))
                name = input("姓名:")
                score = int(input("成绩:"))
                stu = Info(num,name,score)
                menu.aped(stu)
            elif key == 2:
                menu.display()
            elif key == 3:
                menu.writearead(1)
            elif key == 4:
                menu.writearead(2)
            else:
                print("输入错误")
